package com.gitee.faster.webdav.common.constant;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author hongda.li
 */
@Getter
public enum MethodEnum {

    PROPFIND,

    PROPPATCH,

    MKCOL,

    PUT,

    GET,

    DELETE,

    COPY,

    MOVE,

    LOCK,

    UNLOCK,

    OPTIONS,

    POST,

    /**
     * 暂不支持的方法
     */
    UNSUPPORTED;

    private static final Map<String, MethodEnum> LOOKUP;

    static {
        LOOKUP = Arrays.stream(MethodEnum.values()).collect(Collectors.toMap(Enum::name, Function.identity()));
    }

    public static MethodEnum byName(String name) {
        return Optional.ofNullable(LOOKUP.get(name)).orElse(MethodEnum.UNSUPPORTED);
    }
}
